package com.sanno.patient.util;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Component
public class RedisUtil {
    @Resource
    RedisTemplate<String, Object> redisTemplate;

    public void set(final String key,final Object val){
        System.out.println(redisTemplate);
        redisTemplate.opsForValue().set(key,val);
    }
    public Object get(final Object key){
        return redisTemplate.opsForValue().get(key);
    }
    public void update(final String key, String value) {
        redisTemplate.opsForValue().getAndSet(key, value);
    }
    public void delete(final String key) {
        redisTemplate.delete(key);
    }
    public boolean has(String key) {
        return redisTemplate.hasKey(key);
    }
    public boolean expire(String key, long expire) {
        return redisTemplate.expire(key, expire, TimeUnit.SECONDS);
    }
    public Long increment(String key, long delta) {
        return redisTemplate.opsForValue().increment(key, delta);
    }
}
